<?php
class SiteSaveSpiderAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	public function execute()
	{
		$data		= array();
		$spiders	= C('LtConfig')->get('spiders');
		
		//获取数据
		foreach($spiders as $spider)
		{
			$val = $this->context->post($spider['en']);
			if(is_numeric($val) && $val>0)
			{
				$val	= 1;
			}
			else
			{
				$val	= 0;
			}
			$data[$spider['en']]	= $val;
		}
		
		//保存
		$settingService	= new SettingService();
		$skey			= 'spider_setting';
		$tmp			= $settingService->get($skey);
		if(!$tmp)
		{
			$settingService->add($skey,$data,true);
		}
		else
		{
			$settingService->update($skey,$data,false,true);
		}
		
		$this->code	= 200;
	}
}
